<script>
	var url<?=$objectid?>;
	$(document).ready(function(){
	
		newData<?=$objectid?> = function (){
			$('#window<?=$objectid?>').dialog({
				title: 'Tambah Data Pembayaran PSB',
				width: 450,
				//height: $(window).height() * 0.99,
				height: 200,
				closed: true,
				cache: false,
				href: base_url+'sd/setting/pembayaran_psb/add',
				modal: true,
				style:{background:'#dee5ff'}
			});
			 
			$('#window<?=$objectid?>').dialog('open');
			url<?=$objectid?> = base_url+'sd/setting/pembayaran_psb/save/add';
		}
		// end newData
		
		editData<?=$objectid?> = function (val){
			// var row = $('#dg').datagrid('getSelected');
			// if (row){
				$('#window<?=$objectid?>').dialog({
					title: 'Edit Data Pembayaran PSB',
					width: 450,
					height: 200,
					closed: true,
					cache: false,
					href: base_url+'sd/setting/pembayaran_psb/edit/'+val,
					modal: true
				});
				
				$('#window<?=$objectid?>').dialog('open');  
				url<?=$objectid?> = base_url+'sd/setting/pembayaran_psb/save/edit';
			// }
		}
		//end editData
		
		deleteData<?=$objectid?> = function (val){
			// var row = $('#dg').datagrid('getSelected');
			// if(row){
				if(confirm("Apakah yakin akan menghapus data '" + val + "'?")){
					var response = '';
					$.ajax({ type: "GET",
						 url: base_url+'sd/setting/pembayaran_psb/delete/' + val,
						 async: false,
						 success : function(response){
							var response = eval('('+response+')');
							if (response.success){
								$.messager.show({
									title: 'Success',
									msg: 'Data Berhasil Dihapus'
								});
								// reload and close tab
								$('#dg<?=$objectid?>').datagrid('reload');
							} else {
								MessageError(response.msg);
							}
						 }
					});
				}
			// }
		}
		//end deleteData 
		
		saveData<?=$objectid?> = function(){
			$('#form1<?=$objectid?>').form('submit',{
				url: url<?=$objectid?>,
				onSubmit: function(){
					return $(this).form('validate');
				},
				success: function(result){
					//alert(result);
					var result = eval('('+result+')');
					if (result.success){
						$('#window<?=$objectid?>').dialog('close');		// close the dialog
						$('#dg<?=$objectid?>').datagrid('reload');		// reload the user data
					} else {
						ShowMessageError(result.msg);
					}
				}
			});
		}
		//end saveData
		
		actionbutton<?=$objectid?> = function(value, row, index){
			var col="";
			//if (row.kd_pegawai != null) {
				
				col += '<a href="#" onclick="editData<?=$objectid?>(\''+row.id+'\');" class="easyui-linkbutton" iconCls="icon-edit" plain="false">Edit</a>';
				
				col += '&nbsp;&nbsp;&nbsp;';
				
				col += '<a href="#" onclick="deleteData<?=$objectid?>(\''+row.id+'\');" class="easyui-linkbutton" iconCls="icon-edit" plain="false">Delete</a>';
				
			//}
			return col;
		}
		
		// init
		$(function(){
			$('#dg<?=$objectid?>').datagrid({
				url:"<?=base_url()?>sd/setting/pembayaran_psb/grid"
			});
		});
		
		// filter
		filter<?=$objectid?> = function(){
			$('#dg<?=$objectid?>').datagrid('load',{
				//kd_pt : $('#s_kd_pt').val(),
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		// formatter
		format_status<?=$objectid?> = function(value, field, index){
			return value==1?'Aktif':'Tidak Aktif';
		}
		
		//# Tombol Bawah
		$(function(){
			var pager = $('#dg<?=$objectid?>').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
					
					{
						iconCls:'icon-add',
						text:'Tambah Data',
						handler:function(){
							newData<?=$objectid?>();
						}
					}
					
				]
			});			
		});
		
	});
</script>
<table id="dg<?=$objectid?>" title="Kelola Data Pembayaran : <?=$this->mdl_proses_penerimaan->get_title_penerimaan()?>, <?=$this->mdl_kelompok_penerimaan->get_title_kelompok()?> Tahun <?=$this->mdl_proses_penerimaan->get_title_tahun()?>" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			onLoadSuccess: function(data){
				ShowGridMessage(this, 'Tidak Terdapat Data');
			},
			">
	<thead data-options="frozen:true">
		<tr>
			<th field="action" align="center" formatter="actionbutton<?=$objectid?>" width="100">Aksi</th>
		</tr>
	</thead>
	<thead>
		<tr>
			<th field="id" hidden="true" width="120"></th>
			<th field="posisi" width="70">Posisi</th>
			<th field="pembayaran" width="250">Pembayaran</th>
			<th field="nominal" align="right" width="130">Nominal (Rp.)</th>
		</tr>
	</thead>
</table>

<!-- AREA untuk Form Add/EDIT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  -->
<div id="window<?=$objectid?>" class="easyui-dialog" style="width:400px;height:150px;padding:10px;" data-options="
		closed:true,
		minimizable:false,
		collapsible:false,
		maximizable:false,
		buttons:[{
					text:'Save',
					iconCls:'icon-ok',
					handler:function(){ saveData<?=$objectid?>(); }
				},{
					text:'Close',
					iconCls:'icon-cancel',
					handler:function(){ $('#window<?=$objectid?>').dialog('close') }
				}],
		onResize:function(){
			$(this).window('center');
		}"
>
</div>